package com.aier.proxy.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.common.common.Constant;
import com.aier.common.dao.ICommonDAO;
import com.aier.entrance.common.EntranceICFinalData;
import com.aier.entrance.entity.EntranceDevice;
import com.aier.proxy.comm.ProxyEquipPageSize;
import com.aier.proxy.service.IProxyService;
import com.aier.school.entity.School;

@Scope("prototype")
@Component("proxyEntranceAction")
public class ProxyEntranceAction extends ProxyBaseAction {
    /**
     * 门禁
     */
    private static final long serialVersionUID = 1L;

    @Resource(name = "proxyService")
    private IProxyService proxyService;

    private List<School> schoolsList;
    // 代理商id
    private Integer pid;
    // 设备编号
    private String sn;
    // 学校id
    private Integer sid;
    // 派属
    private Integer poxystate;
    // 状态
    private Integer state;
    // 设备id
    private Long eid;
    // 拍照状态
    private Short vdstate;

    // 页数
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    // 排序方式
    private String sord;
    // 排序字段
    private String sort;

    private int s;

    private List<EntranceDevice> eds;

    @Override
    public String execute() {

        schoolsList = proxyService.searchSchoolsByPid(pid);

        return SUCCESS;
    }

    /**
     * 查询门禁设备信息
     * 
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchEntranceInfo() {

        if (page <= 0) {
            page = 1;
        }
        int sortable = -1;
        if ("sn".equals(sort)) {
            sortable = ("asc".equals(sord)) ? IProxyService.ENTRANCE_SORTABLE_SN
                    : IProxyService.ENTRANCE_SORTABLE_SN_DESC;
        }
        Map<String, Object> map = proxyService.searchEntDevicesByCondition(
                page, ProxyEquipPageSize.PROXY_ENTRANCE_PAGESIZE, sortable,
                pid, sid, state, poxystate, sn);
        if (null == map) {
            s = Constant.num_1000;
            return ERROR;
        }
        eds = (List<EntranceDevice>) map.get(ICommonDAO.OBJ_LIST);
        if (null == eds) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        return SUCCESS;

    }

    // 遍历学校数据
    public String selschools() {
        schoolsList = proxyService.searchSchoolsByPid(pid);
        return SUCCESS;
    }

    // 修改门禁设备信息
    public String pec_update() {
        s = proxyService.updateEntranceByEid(eid, state.shortValue(), vdstate,
                sid);
        return SUCCESS;
    }

    //删除门禁
    public String pec_delete() {
        s = proxyService.updateEntranceToScrappedByEid(eid, EntranceICFinalData.ENTRANCE_STATE_DEL);
        return SUCCESS;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public List<School> getSchoolsList() {
        return schoolsList;
    }

    public void setProxyService(IProxyService proxyService) {
        this.proxyService = proxyService;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public void setSord(String sord) {
        this.sord = sord;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public int getS() {
        return s;
    }

    public List<EntranceDevice> getEds() {
        return eds;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public void setPoxystate(Integer poxystate) {
        this.poxystate = poxystate;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public void setVdstate(Short vdstate) {
        this.vdstate = vdstate;
    }

    public void setEid(Long eid) {
        this.eid = eid;
    }

}
